package com.flying.invest.assets.model;

import java.util.Date;

import com.flying.common.util.Codes;
import com.flying.framework.annotation.ConstantEnum;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.ServiceField;
import com.flying.framework.annotation.ServiceFieldParam;
import com.flying.framework.data.Data;
import com.flying.framework.data.DataSerializable;
import com.flying.framework.metadata.Meta;
import com.flying.invest.assets.RiskLevel;

@SuppressWarnings("serial")
@Meta(id="i_assets",title="投资品种", table="i_assets", primaryKeys={"assets_id"})
public class Assets extends Data implements DataSerializable {
	public final static String ENTITY_NAME = "i_assets";
	
	public final static String ASSETS_ID = "assets_id";
	public final static String TYPE_ID = "type_id";
	public final static String MARKET_ID = "market_id";
	public final static String BLOCK_ID = "block_id";
	public final static String NAME = "name";
	public final static String CODE = "code";
	public final static String INDUSTRY = "industry";
	public final static String STATUS = "status";
	public final static String PRICE = "price";
	public final static String PRICE_DATE = "price_date";
	public final static String UNIT = "unit";
	public final static String TAX_RATE = "tax_rate";
	public final static String RISK_LEVEL = "risk_level";
	public final static String REGION = "region";
	public final static String REMARKS = "remarks";
	public final static String UPDATE_TIME = "update_time";
	public final static String CURRENCY = "currency";
	public final static String SPIDER_SERVICE = "spider_service";

	public final static String MAX_PRICE_M3 = "max_price_m3";
	public final static String MIN_PRICE_M3 = "min_price_m3";
	public final static String MAX_PRICE_M6 = "max_price_m6";
	public final static String MIN_PRICE_M6 = "min_price_m6";
	public final static String MAX_PRICE_M12 = "max_price_m12";
	public final static String MIN_PRICE_M12 = "min_price_m12";
	
	public enum Status implements ConstantEnum<Integer> {
		INVALID(0, "不在用"), VALID(1, "在用");

		public final int value;
		public final String remarks;

		Status(int value, String remarks) {
			this.value = value;
			this.remarks = remarks;
		}
		
		@Override
		public Integer value() {
			return this.value;
		}

		@Override
		public String text() {
			return remarks;
		}
	}
	
	
	@Param(value=ASSETS_ID,   required=true,   maxlength=0,	desc="ASSETS ID" , generator=Codes.AUTO_INCREMENT)
	private Long assetsId;
	
	@Param(value=TYPE_ID,   required=false,   maxlength=0,	desc="类型ID" )
	private Long typeId;
	
	@Param(value=MARKET_ID,   required=false,   maxlength=0,	desc="市场ID" )
	private Long marketId;
	
	@Param(value=BLOCK_ID,   required=false,   maxlength=0,	desc="板块ID" )
	private Long blockId;
	
	@Param(value=NAME,   required=false,   maxlength=50,	desc="名称" )
	private String name;
	
	@Param(value=CODE,   required=false,   maxlength=10,	desc="代码" )
	private String code;
	
	@Param(value=INDUSTRY,   required=false,   maxlength=20,	desc="行业" )
	private String industry;
	
	@Param(value=STATUS,   required=false,   maxlength=0,	desc="状态（0：无效；1：有效）", enumClass=Status.class )
	private Integer status;
	
	@Param(value=PRICE,   required=false,   maxlength=0,	desc="最新价格" )
	private Double price;
	
	@Param(value=PRICE_DATE,   required=true,   maxlength=0,	desc="价格日期" )
	private Date priceDate;
	
	@Param(value=UNIT,   required=false,   maxlength=10,	desc="单位" )
	private String unit;
	
	@Param(value=TAX_RATE,   required=false,   maxlength=0,	desc="交易税率" )
	private Double taxRate;
	
	@Param(value=RISK_LEVEL,   required=false,   maxlength=0, enumClass=RiskLevel.class,	desc="风险等级" )
	private Integer riskLevel;
	
	@Param(value=REGION,   required=false,   maxlength=40,	desc="所属区域（美国、欧洲等）" )
	private String region;
	
	@Param(value=REMARKS,   required=false,   maxlength=400,	desc="说明" )
	private String remarks;
	
	@Param(value=UPDATE_TIME,   required=false,   maxlength=0,	desc="更新时间" )
	private Date updateTime;
	
	@Param(value=CURRENCY,   required=true,   maxlength=10,	desc="币种" )
	private String currency;
	
	@Param(value=SPIDER_SERVICE,   required=true,   maxlength=10,	desc="价格爬虫" )
	private String spiderService;
	
	//
	@Param(value=MAX_PRICE_M3,   required=false,   maxlength=0,	desc="3个月最高价格" )
	private Double maxPriceM3;

	@Param(value=MIN_PRICE_M3,   required=false,   maxlength=0,	desc="3个月最低价格" )
	private Double minPriceM3;

	@Param(value=MAX_PRICE_M6,   required=false,   maxlength=0,	desc="6个月最高价格" )
	private Double maxPriceM6;

	@Param(value=MIN_PRICE_M6,   required=false,   maxlength=0,	desc="6个月最低价格" )
	private Double minPriceM6;

	@Param(value=MAX_PRICE_M12,   required=false,   maxlength=0,	desc="12个月最高价格" )
	private Double maxPriceM12;

	@Param(value=MIN_PRICE_M12,   required=false,   maxlength=0,	desc="12个月最低价格" )
	private Double minPriceM12;
	
	//
	@ServiceField(serviceId="AssetsTypeService:findById", params={@ServiceFieldParam(param=AssetsType.TYPE_ID, value="$"+TYPE_ID)})
	@Param(value="assetsType",   required=false,	desc="资产类型", ignored=true)
	private AssetsType assetsType;

	@ServiceField(serviceId="AssetsMarketService:findById", params={@ServiceFieldParam(param=AssetsMarket.MARKET_ID, value="$"+MARKET_ID)})
	@Param(value="market",   required=false,	desc="资产类型", ignored=true)
	private AssetsMarket market;

	@ServiceField(serviceId="AssetsBlockService:findById", params={@ServiceFieldParam(param=AssetsBlock.BLOCK_ID, value="$"+BLOCK_ID)})
	@Param(value="block",   required=false,	desc="资产类型", ignored=true)
	private AssetsBlock block;
	
	public Long getAssetsId() {
		return this.assetsId;
	}
	
	public void setAssetsId(Long assetsId) {
		this.assetsId = assetsId;
	}

	public Long getTypeId() {
		return this.typeId;
	}
	
	public void setTypeId(Long typeId) {
		this.typeId = typeId;
	}
	
	public Long getMarketId() {
		return marketId;
	}

	public void setMarketId(Long marketId) {
		this.marketId = marketId;
	}

	public Long getBlockId() {
		return blockId;
	}

	public void setBlockId(Long blockId) {
		this.blockId = blockId;
	}

	public String getName() {
		return this.name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getCode() {
		return this.code;
	}
	
	public void setCode(String code) {
		this.code = code;
	}
	
	public String getIndustry() {
		return this.industry;
	}
	
	public void setIndustry(String industry) {
		this.industry = industry;
	}
	
	public Integer getStatus() {
		return this.status;
	}
	
	public void setStatus(Integer status) {
		this.status = status;
	}
	
	public Double getPrice() {
		return this.price;
	}
	
	public void setPrice(Double price) {
		this.price = price;
	}
	
	public Date getPriceDate() {
		return priceDate;
	}

	public void setPriceDate(Date priceDate) {
		this.priceDate = priceDate;
	}

	public String getUnit() {
		return this.unit;
	}
	
	public void setUnit(String unit) {
		this.unit = unit;
	}
	
	public Double getTaxRate() {
		return this.taxRate;
	}
	
	public void setTaxRate(Double taxRate) {
		this.taxRate = taxRate;
	}
	
	public Integer getRiskLevel() {
		return this.riskLevel;
	}
	
	public void setRiskLevel(Integer riskLevel) {
		this.riskLevel = riskLevel;
	}
	
	public String getRegion() {
		return this.region;
	}
	
	public void setRegion(String region) {
		this.region = region;
	}
	
	public String getRemarks() {
		return this.remarks;
	}
	
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	
	public Date getUpdateTime() {
		return this.updateTime;
	}
	
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
	public String getCurrency() {
		return this.currency;
	}
	
	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public String getSpiderService() {
		return spiderService;
	}

	public void setSpiderService(String spiderService) {
		this.spiderService = spiderService;
	}

	public Double getMaxPriceM3() {
		return maxPriceM3;
	}

	public void setMaxPriceM3(Double maxPriceM3) {
		this.maxPriceM3 = maxPriceM3;
	}

	public Double getMinPriceM3() {
		return minPriceM3;
	}

	public void setMinPriceM3(Double minPriceM3) {
		this.minPriceM3 = minPriceM3;
	}

	public Double getMaxPriceM6() {
		return maxPriceM6;
	}

	public void setMaxPriceM6(Double maxPriceM6) {
		this.maxPriceM6 = maxPriceM6;
	}

	public Double getMinPriceM6() {
		return minPriceM6;
	}

	public void setMinPriceM6(Double minPriceM6) {
		this.minPriceM6 = minPriceM6;
	}

	public Double getMaxPriceM12() {
		return maxPriceM12;
	}

	public void setMaxPriceM12(Double maxPriceM12) {
		this.maxPriceM12 = maxPriceM12;
	}

	public Double getMinPriceM12() {
		return minPriceM12;
	}

	public void setMinPriceM12(Double minPriceM12) {
		this.minPriceM12 = minPriceM12;
	}

	public AssetsType getAssetsType() {
		return assetsType;
	}

	public AssetsMarket getMarket() {
		return this.market;
	}
	
	public AssetsBlock getBlock() {
		return block;
	}

	public String getAssetsTypeName() {
		AssetsType t = this.getAssetsType();
		if(t != null) {
			return t.getName();
		} else {
			return null;
		}
	}
	
	public String getMarketName() {
		AssetsMarket t = this.getMarket();
		if(t != null) {
			return t.getName();
		} else {
			return null;
		}
	}
	
	public String getBlockName() {
		AssetsBlock t = this.getBlock();
		if(t != null) {
			return t.getName();
		} else {
			return null;
		}
	}
	//
	public Double getFellRateM3() {
		if(this.getPrice() != null && this.getMaxPriceM3() != null) {
			return (this.getMaxPriceM3() - this.getPrice()) / this.getMaxPriceM3() * 100;
		} else {
			return null;
		}
	}
	
	public Double getRiseRateM3() {
		if(this.getPrice() != null && this.getMinPriceM3() != null) {
			return (this.getPrice() - this.getMinPriceM3()) / this.getMinPriceM3() * 100;
		} else {
			return null;
		}
	}

	public Double getFellRateM6() {
		if(this.getPrice() != null && this.getMaxPriceM6() != null) {
			return (this.getMaxPriceM6() - this.getPrice()) / this.getMaxPriceM6() * 100;
		} else {
			return null;
		}
	}
	
	public Double getRiseRateM6() {
		if(this.getPrice() != null && this.getMinPriceM6() != null) {
			return (this.getPrice() - this.getMinPriceM6()) / this.getMinPriceM6() * 100;
		} else {
			return null;
		}
	}

	public Double getFellRateM12() {
		if(this.getPrice() != null && this.getMaxPriceM12() != null) {
			return (this.getMaxPriceM12() - this.getPrice()) / this.getMaxPriceM12() * 100;
		} else {
			return null;
		}
	}
	
	public Double getRiseRateM12() {
		if(this.getPrice() != null && this.getMinPriceM12() != null) {
			return (this.getPrice() - this.getMinPriceM12()) / this.getMinPriceM12() * 100;
		} else {
			return null;
		}
	}
}